{extend name="admin/public/base" /}

{block name="content"}
<!-- Content Header (Page header) -->
<section class="content-header">
  <h1>
    用户更新
    <small></small>
  </h1>
  <ol class="breadcrumb">
    <li><a href="#"><i class="fa fa-dashboard"></i> 首页</a></li>
    <li><a href="#">用户</a></li>
    <li class="active">用户更新</li>
  </ol>
</section>

<!-- Main content -->
<section class="content">

    <div class="box box-solid">
        <div class="box-body no-padding">
           <form method="post" id="form" action="" class="form-horizontal">
              <!-- Custom Tabs -->
              <div class="nav-tabs-custom">
                <ul class="nav nav-tabs">
                  <li class="active"><a href="#tab_1" data-toggle="tab">基本信息</a></li>
                  <li><a href="#tab_2" data-toggle="tab">其他信息</a></li>
                </ul>
                <div class="tab-content">
                  <div class="tab-pane active" id="tab_1">
                        <div class="form-group">
                            <label class="col-sm-2 control-label">账户</label>
                            <div class="col-sm-5">
                                <input type="text" name="username" value="{$data.userInfo.username}" class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">密码</label>
                            <div class="col-sm-5">
                                <input type="password" id="password" name="password" class="form-control">
                                <span class="help-block m-b-none">默认为空则不修改密码.</span>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">确认密码</label>
                            <div class="col-sm-5">
                                <input type="password" name="confirm_password" class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">电子邮箱</label>
                            <div class="col-sm-5">
                                <input type="text" name="email" value="{$data.userInfo.email}" class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">电话号码</label>
                            <div class="col-sm-5">
                                <input type="text" name="phone" value="{$data.userInfo.phone}" class="form-control">
                            </div>
                        </div>
                  </div>
                  <div class="tab-pane" id="tab_2">
                        <div class="form-group">
                            <label class="col-sm-2 control-label">权限组</label>
                            <div class="col-sm-2">
                                <select class="form-control" name="group_id">
                                    {volist name="data.groupList" id="vo"}
                                    <option {eq name="data.userInfo.group_id" value="$vo.id"}selected{/eq} value="{$vo.id}">{$vo.name}</option>
                                    {/volist}
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">用户性别</label>
                            <div class="col-sm-5">
                                <label class="radio-inline">
                                    <input {eq name="data.userInfo.sex" value="1"}checked{/eq} type="radio" value="1" name="sex">
                                    男
                                </label>
                                <label class="radio-inline">
                                    <input {eq name="data.userInfo.sex" value="2"}checked{/eq} type="radio" value="2" name="sex">
                                    女
                                </label>
                                <label class="radio-inline">
                                    <input {eq name="data.userInfo.sex" value="0"}checked{/eq} type="radio" value="0" name="sex">
                                    未知
                                </label>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">后台用户</label>
                            <div class="col-sm-5">
                                <label  class="checkbox-inline">
                                    <input {eq name="data.userInfo.state" value="1"}checked{/eq} type="checkbox" name="state" value="1">
                                    是
                                </label>
                            </div>
                        </div>
                  </div>
                  <!-- /.tab-pane -->
                </div>
                <!-- /.tab-content -->
              </div>
              <!-- nav-tabs-custom -->
              <div class="form-group">
                <div class="col-sm-offset-2 col-sm-10">
                    <div class="btn-group">
                        <input type="hidden" name="uid" value="{$data.userInfo.uid}" >
                        <button class="btn btn-default btn-flat" type="reset">取消</button>
                        <button class="btn btn-primary btn-flat" type="submit">保存</button>
                    </div>
                </div>
              </div>
            </form>
        </div>
    </div>

</section>
<!-- /.content -->
{/block}

{block name="js"}
<script>

    $(function(){

        $("form").validate({
            rules: {
                username: {
                    required: true,
                    minlength: 3,
                    maxlength: 32
                },
                password: {
                    required: false,
                    minlength: 6,
                    maxlength: 32
                },
                confirm_password: {
                    required: false,
                    minlength: 6,
                    maxlength: 32,
                    equalTo: "#password"
                },
                email: {
                    required: true,
                    email: true
                },
                phone: {
                    required: true,
                    number: true
                }
            },
            submitHandler: function(form) {
                <!-- alert("submitted!"); -->
                $.ajax({
                    url:"{:Url('admin/user/update')}",
                    data:$(form).serialize(),
                    type:'post',
                    dataType:'json',
                    success:function(xhr){
                        if(xhr.code == 200){
                            swal({
                                title: xhr.msg,
                                text: "",
                                type: "success",
                                confirmButtonText: '确定',
                                cancelButtonText: '取消',
                            });
                        } else{
                            swal({
                                title: xhr.msg,
                                text: "",
                                type: "error",
                                confirmButtonText: '确定',
                                cancelButtonText: '取消',
                            });
                        }
                    }
                });

            }
        });

    });
</script>
{/block}